package com.imgdpicheck.utils;

import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;

import java.io.File;
import java.io.IOException;

/**
 * @author xuehu
 * @date 2021/1/28 10:27
 * 获取图片的dpi值的工具类
 */

public class ImgCheckUtil {

    //获取垂直dpi
    public static Integer getImageHeightDpiByFile(File file) {
        ImageInfo imageInfo = null;
        try {
            imageInfo = Imaging.getImageInfo(file);
        } catch (ImageReadException | IOException e) {
            e.printStackTrace();
        }
        return imageInfo.getPhysicalHeightDpi();
    }

    //获取水平dpi
    public static Integer getImageWidthDpiByFile(File file) {
        ImageInfo imageInfo = null;
        try {
            imageInfo = Imaging.getImageInfo(file);
        } catch (ImageReadException | IOException e) {
            e.printStackTrace();
        }
        return imageInfo.getPhysicalWidthDpi();
    }


    //获取变量的数据类型
    private static String getType(Object a) {
        return a.getClass().toString();

    }


}
